<?php

/**
 * This is the model class for table "rekening".
 *
 * The followings are the available columns in table 'rekening':
 * @property string $id_rekening
 * @property string $no_rekening
 * @property string $nama_rekening
 * @property double $tarif
 * @property string $status
 * @property string $tampil
 * @property string $keterangan
 * @property string $kode_pajak
 *
 * The followings are the available model relations:
 * @property SptpdAirtanah[] $sptpdAirtanahs
 * @property SptpdHiburan[] $sptpdHiburans
 * @property SptpdReklame[] $sptpdReklames
 * @property SptpdRestoran[] $sptpdRestorans
 * @property SptpdParkir[] $sptpdParkirs
 * @property SptpdHotel[] $sptpdHotels
 * @property ReklameJenis[] $reklameJenises
 * @property Sspd[] $sspds
 * @property SptpdGalianc[] $sptpdGaliancs
 */
class Rekening extends CActiveRecord
{
    public $nama_pajak;
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'rekening';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('id_rekening', 'required'),
			array('tarif', 'numerical'),
			array('no_rekening', 'length', 'max'=>20),
			array('nama_rekening', 'length', 'max'=>100),
			array('status, tampil', 'length', 'max'=>2),
			array('keterangan', 'length', 'max'=>250), 
                        array('kode_pajak', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id_rekening, no_rekening, nama_rekening, tarif, status, tampil, keterangan, kode_pajak', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'kodePajak' => array(self::BELONGS_TO, 'Pajak', 'kode_pajak'),
                        'sptpdAirtanahs' => array(self::HAS_MANY, 'SptpdAirtanah', 'id_rekening'),
			'sptpdHiburans' => array(self::HAS_MANY, 'SptpdHiburan', 'id_rekening'),
			'sptpdReklames' => array(self::HAS_MANY, 'SptpdReklame', 'id_rekening'),
			'sptpdRestorans' => array(self::HAS_MANY, 'SptpdRestoran', 'id_rekening'),
			'sptpdParkirs' => array(self::HAS_MANY, 'SptpdParkir', 'id_rekening'),
			'sptpdHotels' => array(self::HAS_MANY, 'SptpdHotel', 'id_rekening'),
			'reklameJenises' => array(self::HAS_MANY, 'ReklameJenis', 'id_rekening'),
			'sspds' => array(self::HAS_MANY, 'Sspd', 'id_rekening'),
			'sptpdGaliancs' => array(self::HAS_MANY, 'SptpdGalianc', 'id_rekening'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id_rekening' => 'Id Rekening',
			'no_rekening' => 'No Rekening',
			'nama_rekening' => 'Nama Rekening',
			'tarif' => 'Tarif',
			'status' => 'Status',
			'tampil' => 'Tampil',
			'keterangan' => 'Keterangan',
			'kode_pajak' => 'Kode Pajak',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		$criteria=new CDbCriteria;
                $criteria->alias="r";
                $criteria->select = 'r.*, p.nama_pajak';
                $criteria->join = 'inner join pajak p ON r.kode_pajak = p.kode_pajak';

            // @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id_rekening',$this->id_rekening,true);
		$criteria->compare('no_rekening',$this->no_rekening,true);
		$criteria->compare('nama_rekening',$this->nama_rekening,true);
		$criteria->compare('tarif',$this->tarif);
		$criteria->compare('status',$this->status,true);
		$criteria->compare('tampil',$this->tampil,true);
		$criteria->compare('keterangan',$this->keterangan,true);
		$criteria->compare('kode_pajak',$this->kode_pajak,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Rekening the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
